package q965_isUnivalTree;
import CommonClass.Common.TreeNode;
public class Solution_2 {
    /*
    DFS
     */
    public boolean isUnivalTree(TreeNode root) {
        if (root == null) {
            return true;
        }

        if (root.left != null) {
            if (root.val != root.left.val || !isUnivalTree(root.left)) {
                return false;
            }
        }

        if (root.right != null) {
            if (root.val != root.right.val || !isUnivalTree(root.right)) {
                return false;
            }
        }

        return true;
    }
}
